package com.netty.server;

import java.net.InetAddress;
import java.net.UnknownHostException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.qbb.server.exception.HandlerException;

/**
 * 类说明
 * 
 * @author chenhuaiao
 * @version V1.0 创建时间：Mar 9, 2015 4:02:10 PM
 */
public class QbbServerThread implements Runnable {
	private static Log log = LogFactory.getLog(QbbServerThread.class);
	private Integer port;

	public QbbServerThread(Integer port) {
		this.port = port;
	}

	/**
	 * thread start
	 */
	public void run() {
		String ip = getIp();

		String info = "QbbServer start port,ip:[" + ip + "],port:[" + port
				+ "] ";
		log.info(info);
		// 启动端口
		try {
			StartServerPort.bind(port);
		} catch (Exception e) {
			HandlerException.error(e);
		}
	}

	private static String getIp() {
		try {
			InetAddress addr = InetAddress.getLocalHost();
			// 获取本机ip
			String ip = addr.getHostAddress().toString();
			return ip;
		} catch (Exception e) {
			HandlerException.error(e);
		}
		return "";

	}
}
